package com.rsg.graphics;

import java.awt.*;

public class RGraphics_old{
	private GraphicsInter inter=null;
	private Color penCl=Color.white;
	public RGraphics_old(GraphicsInter inter){
		this.inter=inter;
	}

	public void drawPoint(int x,int y){
		inter.drawDot(x, y);
	}
	public void drawLine(int x0,int y0,int x1,int y1) {
		int dx=x1-x0,dyssb=y1-y0;//邓燕是傻逼
		if(Math.abs(dx)>Math.abs(dyssb)) {//长大于高
			int unit=dx/Math.abs(dx);
			double step=(double)dyssb/(double)dx;
			for(int x=x0;Math.abs(x-x1)>0;x+=unit) {
				inter.drawDot(x,(int) (y0+step*(x-x0)));
			}
		}else if(Math.abs(dyssb)>=Math.abs(dx)) {
			int unit=dyssb/Math.abs(dyssb);
			double step=(double)dx/(double)dyssb;
			for(int y=y0;Math.abs(y-y1)>0;y+=unit) {
				inter.drawDot((int) (x0+step*(y-y0)),y);
			}
		}
	}
	private void rect(int x,int y,int w,int h,boolean fill){
		for(int i=0;i<=h;i++){
			for(int j=0;j<=w;j++){
				if(j>0&&i>0&&j<(w)&&i<(h)){
					if(fill) {
						inter.drawDot(j + x, i + y);
					}else {
						continue;
					}
				}else{
					//System.out.println("paint");
					inter.drawDot(j+x,i+y);
				}
			}
		}
	}
	public void drawRect(int x,int y,int width,int height){
		rect(x,y,width,height,false);
	}
	public void fillRect(int x,int y,int width,int height){
		rect(x,y,width,height,true);
	}


	public void oval(int x,int y,int width,int height,boolean fill){

	}
	public void drawOval(int x,int y,int width,int height){
		oval(x,y,width,height,false);
	}
	public void fillOval(int x,int y,int width,int height){
		oval(x,y,width,height,true);
	}
	/*public void drawPixelImage(int x,int y,PixelImage pi){
		for(int i=0;i<pi.getHeight();i++){
			for(int j=0;j<pi.getWidth();j++){
				if(pi.bitMap[i][j]=='T'||pi.bitMap[i][j]=='N'){
					continue;
				}
				this.setColor(pi.getColor(pi.bitMap[i][j]));
				this.inter.drawDot(x+j,y+i);
			}
		}
	}*/

	//getter&setter

	public void setColor(Color cl){
		this.penCl=new Color(cl.getRGB());
		this.inter.setColor(cl);
	}
	public Color getColor(){
		return new Color(penCl.getRGB());
	}
}
